home *** CD-ROM | disk | FTP | other *** search
/ Ford Galaxy MK1 Restyling Interactive Presentation / Ford Galaxy.iso / multimedia.dxr / 00038_Zoom In-Out.ls < prev    next >
Encoding:
Text File  |  2001-02-13  |  5.5 KB  |  166 lines

  1. property pSprite, pSpriteRect, pStart, pActive, pStartRect, pDestRect, pDiffRect, pCompleteCycles, pText, pZoomed, pAuto, pTargetH, pTargetV, pCycles, pPeriodBase, pPeriod
  2.  
  3. on getBehaviorDescription me
  4.   return "ZOOM IN/OUT" & RETURN & RETURN & "Gives the appearance of a sprite zooming in (getting larger) or zooming out (smaller). " & "Can be used with animated GIF, bitmap, Flash, QuickTime, text, and vector shape sprites." & RETURN & RETURN & "Place the sprite in its desired zoomed-in position, then add the behavior to the sprite. " & "Choose whether the sprite should zoom in or out, when the zooming should start, the coordinates for the zoomed-out sprite, the number of times it should zoom, and how fast it should zoom. " & "The default zoomed-out position is the center of the sprite." & RETURN & RETURN & "The zoom can be activated automatically in the first frame, by a click on the sprite, or by sending the sprite a mZoomActivate message. " & "See the Notes for Developers in the script for information on this method." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "animated GIF, bitmap, Flash, QuickTime, text, vector shape" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Zoom in or out?" & RETURN & "* Zoom activation (automatic, click, or message)" & RETURN & "* Horizontal and vertical zoom coordinates" & RETURN & "* Number of zoom cycles" & RETURN & "* Time period for zoom in seconds" & RETURN & RETURN & "Set the number of zoom cycles to -1 if you want an endless loop, or to 0 if the zoom should happen only once."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Zooms a sprite in and out. " & "The sprite can zoom in once, multiple times, or continuously."
  9. end
  10.  
  11. on beginSprite me
  12.   pZoomed = resolve(pZoomed)
  13.   pAuto = resolve(pAuto)
  14.   mInitialize(me)
  15. end
  16.  
  17. on resolve prop
  18.   case prop of
  19.     pZoomed:
  20.       choiceslist = ["In", "Out"]
  21.       lookup = [#in, #out]
  22.     pAuto:
  23.       choiceslist = ["Automatic", "Click", "Message"]
  24.       lookup = [#automatic, #click, #message]
  25.   end case
  26.   return lookup[findPos(choiceslist, prop)]
  27. end
  28.  
  29. on prepareFrame me
  30.   mUpdate(me)
  31. end
  32.  
  33. on mouseUp me
  34.   if pAuto = #click then
  35.     mActivate(me)
  36.   end if
  37. end
  38.  
  39. on mInitialize me
  40.   pSprite = sprite(me.spriteNum)
  41.   sprite(pSprite).visible = 1
  42.   pSpriteRect = pSprite.rect
  43.   pActive = 0
  44.   pCompleteCycles = 0.5
  45.   pPeriod = pPeriodBase * 1000
  46.   pText = pSprite.member.type = #text
  47.   vTarget = point(pTargetH, pTargetV)
  48.   if pZoomed = #in then
  49.     vTargetRect = rect(vTarget, vTarget + point(1, 1))
  50.     if pText then
  51.       pSprite.quad = mRecttoQuad(vTargetRect)
  52.     else
  53.       pSprite.rect = vTargetRect
  54.     end if
  55.   end if
  56.   if pAuto = #automatic then
  57.     mActivate(me)
  58.   end if
  59. end
  60.  
  61. on mUpdate me
  62.   if pActive then
  63.     vMillis = the milliSeconds
  64.     vElapsed = vMillis - pStart
  65.     if vElapsed >= pPeriod then
  66.       pActive = 0
  67.       if pText then
  68.         pSprite.quad = mRecttoQuad(pDestRect)
  69.       else
  70.         pSprite.rect = pDestRect
  71.       end if
  72.       mCheckCycle(me)
  73.     else
  74.       vRect = pStartRect + (pDiffRect * vElapsed / pPeriod)
  75.       if pText then
  76.         pSprite.quad = mRecttoQuad(vRect)
  77.       else
  78.         pSprite.rect = vRect
  79.       end if
  80.     end if
  81.   end if
  82. end
  83.  
  84. on mActivate me
  85.   case pZoomed of
  86.     #in:
  87.       mZoomIn(me)
  88.     #out:
  89.       mZoomOut(me, point(pTargetH, pTargetV))
  90.   end case
  91. end
  92.  
  93. on mCheckCycle me
  94.   vContinue = 0
  95.   case pCycles of
  96.     (-1):
  97.       vContinue = 1
  98.     0:
  99.       vContinue = 0
  100.     otherwise:
  101.       pCompleteCycles = pCompleteCycles + 0.5
  102.       if integer(pCompleteCycles) <= pCycles then
  103.         vContinue = 1
  104.       end if
  105.   end case
  106.   if vContinue then
  107.     if pDestRect = pSpriteRect then
  108.       mZoomOut(me, point(pTargetH, pTargetV))
  109.     else
  110.       mZoomIn(me)
  111.     end if
  112.   end if
  113. end
  114.  
  115. on mRecttoQuad vRect
  116.   return [point(vRect.left, vRect.top), point(vRect.right, vRect.top), point(vRect.right, vRect.bottom), point(vRect.left, vRect.bottom)]
  117. end
  118.  
  119. on mZoomIn me
  120.   mZoom(me, pSpriteRect)
  121. end
  122.  
  123. on mZoomOut me, vTarget
  124.   mZoom(me, rect(vTarget, vTarget + point(1, 1)))
  125. end
  126.  
  127. on mZoom me, vDestRect
  128.   pActive = 1
  129.   pStartRect = pSprite.rect
  130.   pDestRect = vDestRect
  131.   pDiffRect = pDestRect - pStartRect
  132.   pStart = the milliSeconds
  133. end
  134.  
  135. on mCenter vRect
  136.   return point(vRect.left + (vRect.width / 2), vRect.top + (vRect.height / 2))
  137. end
  138.  
  139. on mZoomActivate me
  140.   if pAuto = #message then
  141.     mActivate(me)
  142.   end if
  143. end
  144.  
  145. on isOKToAttach me, aSpriteType, aSpriteNum
  146.   case aSpriteType of
  147.     #graphic:
  148.       return getPos([#text, #bitmap, #animGif, #vectorShape, #quickTimeMedia, #flash, #shape], sprite(aSpriteNum).member.type) <> 0
  149.     #script:
  150.       return 0
  151.   end case
  152. end
  153.  
  154. on getPropertyDescriptionList me
  155.   vRect = sprite(the currentSpriteNum).rect
  156.   vCenter = mCenter(vRect)
  157.   vPDList = [:]
  158.   setaProp(vPDList, #pZoomed, [#comment: "Zoom in or out?", #format: #string, #default: "In", #range: ["In", "Out"]])
  159.   setaProp(vPDList, #pAuto, [#comment: "Start automatically, when clicked, or by message?", #default: "Automatic", #format: #string, #range: ["Automatic", "Click", "Message"]])
  160.   setaProp(vPDList, #pTargetH, [#comment: "Horizontal zoom coordinate", #format: #integer, #default: vCenter.locH])
  161.   setaProp(vPDList, #pTargetV, [#comment: "Vertical zoom coordinate", #format: #integer, #default: vCenter.locV])
  162.   setaProp(vPDList, #pCycles, [#comment: "Zoom cycles (0 = one zoom only, -1 = repeat forever)", #format: #integer, #default: 0, #range: [#min: -1, #max: 10]])
  163.   setaProp(vPDList, #pPeriodBase, [#comment: "Time period for zoom (seconds)", #format: #float, #default: 2.0, #range: [#min: 0.25, #max: 15.0]])
  164.   return vPDList
  165. end
  166.